﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using MvcLibrary.Repository;
using System.IO;
using WebVideo.Areas.Admin.Models;

namespace WebVideo.Areas.Admin.Controllers
{
    public class Questions_EssayController : Controller
    {
        //
        // GET: /Admin/Questions_Essay/

        public ActionResult Index(int Id)
        {
            dbVideoDataContext db = new dbVideoDataContext();
          //  EntityVideo g = db.EntityVideos.Where(k=>k.Id == Id).First();
            ViewBag.IdVideo = Id;
            return View(Questions_EssayModel.LayDuLieu (Id));
        }
        #region "Insert"
        public ActionResult Insert(int IdVideo)
        {
            Questions_EssayModel tnew = new Questions_EssayModel();
            tnew.IdVideo = IdVideo;
            return View(tnew);
        }

        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Insert(Questions_EssayModel Mtnew)
        {

            try
            {
                if (ModelState.IsValid)
                {
                    Questions_EssayModel.Insert(Mtnew);
                    return RedirectToAction("Index", "Questions_Essay", new { Id = Mtnew.IdVideo });
                }
            }
            catch
            {

                return RedirectToAction("Index", "Error", new { errorMsg = "Lỗi SQL hosting / server" });
            }
            return View(Mtnew);
        }
        #endregion //insert


        #region "Edit"
        public ActionResult Edit(int IdQVideo)
        {

           
            Questions_EssayModel x = Questions_EssayModel.LayModel(IdQVideo);
            ViewBag.IdVideo = x.IdVideo;
            return View(x);

        }

        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Edit(Questions_EssayModel Mtnew)
        {

            try
            {
                if (ModelState.IsValid)
                {
                    Questions_EssayModel.Edit(Mtnew);
                    return RedirectToAction("Index", "Questions_Essay", new { Id = Mtnew.IdVideo });
                }
            }
            catch
            {

                return RedirectToAction("Index", "Error", new { errorMsg = "Lỗi SQL hosting / server" });
            }
            return View(Mtnew);
        }
        #endregion //Edit

        #region "Delete"

        public string Delete(int Id)
        {
            try
            {
                Questions_EssayModel.Delete(Id);
                return "ok";

            }
            catch
            {
                return "error";

            }

        }

        #endregion //Delete
        public ActionResult TracNgiemHinhAnh(int IdVideo)
        {
            dbVideoDataContext db = new dbVideoDataContext();
            return PartialView(db.EntityQuestions_MultipleChoices.Where(g => g.IdVideo == IdVideo));
        }
    }
}
